import { GCellRenderer } from "../../../../../com/mui/controls/GCellRenderer";
import { PetConfig } from "../../../resource/PetConfig";
import { SPetSkill } from "../../../../../Message/Game/SPetSkill";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { ObjCreate } from "../../common/ObjCreate";
import { GImageBitmap } from "../../../../../com/mui/controls/GImageBitmap";
import { ImagesConst } from "../../../resource/ImagesConst";
import { PetModelPanel } from "../PetModelPanel";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { Language } from "../../../../../extend/language/Language";
import { PetSkillItem } from "../skill/PetSkillItem";
import { Alert } from "../../../../../com/mui/controls/Alert";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { TSkill } from "../../../../../Message/Db/Tables/TSkill";
import { PetSkillsConfig } from "../../../resource/PetSkillsConfig";
import { SkillConfig } from "../../../resource/SkillConfig";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { TCareer } from "../../../../../Message/Db/Tables/TCareer";
import { PetItemInfo } from "../../../resource/info/PetItemInfo";
type int = number;
//class PetEggRandRenderer
    
    export  class PetEggRandRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            this._uid = arg1["uid"] as string;
            this._petItemCode = arg1["petItemCode"] as int;
            this._petItemInfo = PetConfig.instance.getItemInfoByCode(this._petItemCode);
            if (this._petItemInfo) 
            {
                this._type = this._petItemInfo.pet.fightType;
                this._petModel.updateModelByModelId(int(this._petItemInfo.modelId));
                this._nameTxt.text = this._petItemInfo.pet.name;
                this._tskill = this.getTSkill(this._petItemInfo.pet.skill1);
                if (!this._petSkill) 
                {
                    this._petSkill = new SPetSkill();
                }
                this._petSkill.skillId = this._tskill.skillId;
                this._skillItem.skill = this._petSkill;
                LoaderHelp.addResCallBack(ResFileConst.PetEggRand, this.updateBitmap);
            }
            return;
        }

        /* internal  */init(): void
        {
            ObjCreate.createBg(0, 0, 210, 208, this);
            this.addChild(new GImageBitmap(ImagesConst.PetEggRandBg, 5, 5));
            this._petModel = new PetModelPanel();
            this._petModel.x = 106;
            this._petModel.y = 124;
            this.addChild(this._petModel);
            this._typeBitmap = new Object /* flash.display.Bitmap */();
            this._typeBitmap.x = 7;
            this._typeBitmap.y = 7;
            this.addChild(this._typeBitmap);
            this._nameTxt = ObjCreate.createTextField("", 0, 10, 210, 20, this, new GTextFormat(FontUtil.songtiName, 12, 16711935));
            this._nameTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._talentTxt = ObjCreate.createTextField("", 0, 38, 210, 20, this);
            this._talentTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._talentTxt.htmlText = Language.getString(54606);
            ObjCreate.createTextField(Language.getString(54607), 7, 175, 210, 20, this);
            ObjCreate.createBg(70, 167, 38, 38, this, ImagesConst.PackItemBg);
            this._skillItem = new PetSkillItem();
            this._skillItem.setSize(32, 32);
            this._skillItem.move(73, 170);
            this.addChild(this._skillItem);
            this._getBtn = ObjCreate.createGButton(Language.getString(54608), 122, 174, 70, 24, this, "ButtonRed");
            this._getBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onGetBtnClickHandler);
            this._getBtn.drawNow();
            return;
        }

        /* internal  */onGetBtnClickHandler(arg1: Object /* flash.events.Event */): void
        {
            var e: Object /* flash.events.Event */;
            var onClickHandler: Function;

            var loc1;
            e = arg1;
            if (this._petItemInfo) 
            {
                onClickHandler = (arg1: int): void
                {
                    if (arg1 == Alert.OK) 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.PetEggRandUse, {"uid": _uid, "itemCode": _petItemCode}));
                        Alert.resetToDefault();
                    }
                    return;
                }
                Alert.show(Language.getStringByParam(54609, this._petItemInfo.pet.name), null, Alert.OK | Alert.CANCEL, null, onClickHandler);
            }
            return;
        }

        /* internal  */getTSkill(arg1: int): TSkill
        {
            var loc1=null;
            var loc3=null;
            var loc2=PetSkillsConfig.instance.getInfoByCode(arg1);
            if (loc2) 
            {
                if ((loc3 = (loc2.skillsStr.split("#")[0] as string).split(",")).length > 0) 
                {
                    loc1 = SkillConfig.instance.getInfoByName(int(loc3[0]));
                }
            }
            return loc1;
        }

        /* internal  */updateBitmap(): void
        {
            this._typeBitmap.bitmapData = GlobalClass.getBitmapData("PetEggRand" + this._type);
            return;
        }

        /* internal */ /* var */_typeBitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_talentTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_petModel: PetModelPanel;

        /* internal */ /* var */_skillItem: PetSkillItem;

        /* internal */ /* var */_getBtn: GButton;

        /* internal */ /* var */_career: TCareer;

        /* internal */ /* var */_uid: string;

        /* internal */ /* var */_petItemCode: int;

        /* internal */ /* var */_petItemInfo: PetItemInfo;

        /* internal */ /* var */_tskill: TSkill;

        /* internal */ /* var */_petSkill: SPetSkill;

        /* internal */ /* var */_type: int;
    }
